<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>  
  //  for (var i=0;i<10;i++){
  //     setTimeout(() => {
  //       document.write(i + ' ')
  //     }, 0);
  //}
        function test(){
          var arr=[]
          for(var i=0;i<10;i++){
            // arr[i]=function(){
            //   document.write(i+' ')
            // }
            (function(j){
              arr[j]=function(){
              document.write(j+' ')
            }
            })(i)
          }
          return arr
        }
        var myArr =test()
        for(var j=0;j<10;j++){
        myArr[j]()}
  </script>
</body>
</html>